package com.mzy.linear_struct.hot100.滑动窗口;

import java.util.HashMap;

/**
 * @Author: mizy3
 * @Date: 2024/08/20/下午1:50
 * @Description:
 */
public class Pro209长度最小的子数组 {


    private int minSubArrayLen(int target, int[] nums) {
        int ans = Integer.MAX_VALUE;
        int sum = 0;
        int l = 0;
        int r = 0;
        while (r < nums.length) {
            sum += nums[r];
            while (sum >= target) {
                ans = Math.min(ans, r - l + 1);
                sum -= nums[l];
                l++;
            }
            // 2 3 1 2 4 3
            // 0 1 2 3 4 5
            r++;
        }
        return ans == Integer.MAX_VALUE ? 0 : ans;
    }
    public static void main(String[] args) {
        new Pro209长度最小的子数组().minSubArrayLen(11, new int[]{1, 2, 3, 4, 5});
    }

}





























